/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dipl.algorithm.utility.data.comparator;

import dipl.algorithm.math.fp.primitive.Interval1df;

/**
 *
 */
public class IntervalfComparator implements IComparator<Interval1df> {

	//
	// CONSTRUCTOR METHODS
	//

	/**
	 * Constructs a comparator for type integer values.
	 */
	public IntervalfComparator() {
	}

	//
	// PUBLIC METHODS
	//

	/**
	 * Compares intervals.
	 * Intervals are equal if their bounds are equal.
	 * Otherwise first lower-bounds are compared and if they are equal
	 * the upper bounds are compared.
	 * @param a
	 * @param b
	 * @return
	 */
	public int compare( Interval1df a, Interval1df b ) {
		// intervals are ordered by their lower bound first
		double cL = a.L()-b.L();
		double cU = a.U()-b.U();
		if( cL == 0.0 && cU == 0.0 )
			return 0;
		// compare lower bounds
		if( cL > 0.0 ) return 1;
		if( cL < 0.0 ) return -1;
		// lower bounds equal -> now compare upper bounds
		if( cU > 0.0 ) return 1;
		return -1;
	}
}
